import axios from 'axios'
import api from "./server-api";

var _url = api.ip
// var _url = 'http://47.107.159.133:80'

const listApi = (callback) => {
  const url = _url + '/seckill/'
  axios.get(url).then(num => {
    console.log(num.data);
    callback && callback(num.data)
  })
}

const goodsTypesId = (id,callback) => {
  const url = _url + '/goods/byType?typeId=' + id;
  axios.get(url).then(num => {
    console.log(num.data);
    callback && callback(num.data);
  })
}

//添加秒杀商品
const seckillAdd = (listPostSeckill, callback) => {
  var _listPut = new URLSearchParams();
  //添加自动追加id
  _listPut.append("goodsId",listPostSeckill.goodsId);
  _listPut.append("number",listPostSeckill.number);
  _listPut.append("startTime",listPostSeckill.TimeData+' '+listPostSeckill.startTime1);
  _listPut.append("endTime",listPostSeckill.TimeData+' '+listPostSeckill.endTime1);


  const url = _url + '/seckill/?' + _listPut;
  axios.post(url).then(num => {
    callback && callback(num.data);
  })
}


//分页  //添加搜索就用这个
// const pagingList = (val,input,callback) => {
//   var inputUrl;
//   if (input == "" || input == null){
//     inputUrl =  '/goods/page?limit=5&pages='+val
//   }else {
//     inputUrl = '/goods/page?limit=5&pages='+val+'&goodsName=' + input
//   }
//   const url = _url  + inputUrl
//   axios.get(url).then(num => {
//     callback && callback(num.data)
//   })
// }

//删除
const delIdApi = (id, callback) => {
  const url = _url + '/seckill/?seckillId=' + id
  axios.delete(url).then(num => {
    // console.log(num);
    callback && callback(num)
  })
}

//分页
const pagingList = (val,callback) => {
  const url = _url + '/seckill/?limit=5&pages=' + val;
  axios.get(url).then(num => {
    console.log(num.data);
    callback && callback(num.data);
  })
}

export {
  listApi,        // 自动刷新
  goodsTypesId,   //根据小类id遍历出对应的商品
  seckillAdd,     //添加秒杀商品
  pagingList,     //分页
  delIdApi,       //删除
}
